import {ColumnAlign, ColumnInfo} from 'vxe-table/types/column'
import {ColumnCellRenderParams} from 'vxe-table/types/v-x-e-table'
import {ColumnHeaderRenderParams} from 'vxe-table/types/header'
import {ColumnFooterRenderParams} from 'vxe-table/types/footer'
import {ColumnFilterMethodParams, ColumnFilterOption, ColumnFilterRenderOptions} from 'vxe-table/types/filter'
import {ColumnExportCellRenderParams, ColumnExportFooterRenderParams} from 'vxe-table/types/export'
import {ColumnEditRenderOptions} from 'vxe-table/types/edit'
import {ColumnConfig} from 'vxe-table'
import {Vue} from 'vue-property-decorator'
import {RulesItem} from '../elementConfig/index'

export interface MyEditRender<T> extends ColumnEditRenderOptions {
  rules?: RulesItem<T>[]
}


export interface TableHeadItem<T> {
  label?: string;
  minWidth?: string | number;
  width?: string | number;
  prop?: string;
  formatter?: (cellValue: any, row: T, column: ColumnInfo) => string;
  children?: TableHeadItem<T>[];
  fixed?: ColumnAlign;
  /**
   * 列对其方式
   */
  align?: ColumnAlign;
  /**
   * 表头对齐方式
   */
  headerAlign?: ColumnAlign;
  /**
   * 表尾列的对齐方式
   */
  footerAlign?: ColumnAlign;
  /**
   * 当内容过长时显示为省略号
   */
  showOverflow?: boolean | string;
  /**
   * 当表头内容过长时显示为省略号
   */
  showHeaderOverflow?: boolean | string;
  /**
   * 当表尾内容过长时显示为省略号
   */
  showFooterOverflow?: boolean | string;
  /**
   * 给单元格附加 className
   */
  className?: string | ((params: ColumnCellRenderParams) => string | any[] | { [key: string]: boolean });
  /**
   * 给表头单元格附加 className
   */
  headerClassName?: string | ((params: ColumnHeaderRenderParams) => string | any[] | { [key: string]: boolean });
  /**
   * 给表尾单元格附加 className
   */
  footerClassName?: string | ((params: ColumnFooterRenderParams) => string | any[] | { [key: string]: boolean });
  /**
   * 是否允许排序
   */
  sortable?: boolean;
  /**
   * 是否服务端排序
   */
  remoteSort?: boolean;
  /**
   * 自定义排序的属性
   */
  sortBy?: string | string[];

  /**
   * 自定义排序方法
   */
  sortMethod?(a: any, b: any): boolean;

  /**
   * 配置筛选条件数组
   */
  filters?: ColumnFilterOption[];
  /**
   * 筛选是否允许多选
   */
  filterMultiple?: boolean;

  /**
   * 自定义筛选方法
   */
  filterMethod?(params: ColumnFilterMethodParams): boolean;

  /**
   * 筛选模板配置项
   */
  filterRender?: ColumnFilterRenderOptions;
  /**
   * 指定为树节点
   */
  treeNode?: boolean;

  /**
   * 自定义单元格数据导出方法
   */
  exportMethod?(params: ColumnExportCellRenderParams): string | number;

  /**
   * 自定义表尾单元格数据导出方法
   */
  footerExportMethod?(params: ColumnExportFooterRenderParams): string | number;

  /**
   * 单元格编辑渲染配置项
   */
  editRender?: MyEditRender<T>;
}

interface scroll {
  virtualX: boolean;
  virtualY: boolean;
  scrollTop: number;
  scrollLeft: number;
}

export interface MyVxeTableMethods<T> extends Vue {
  scrollToColumn(fieldOrColumn: string | ColumnConfig): Promise<HTMLElement>;

  getScroll(): scroll;

  scrollTo(scrollLeft: number, scrollTop?: number): Promise<any>;

  /**
   * 通过列表field名字滚动到列
   * @param field
   */
  scrollToColumnByField(field: string): Promise<HTMLElement | scroll>;

  /**
   * 组件挂载执行的方法,计算了高度, 可以重新调用计算高度
   */
  vxeGridMounted(): void;

  updateStatus(scope: { row: T, column: ColumnInfo }): Promise<any>;

  clearValidate(): Promise<any>;

  validate(rows?: boolean | T | T[]): Promise<any>
}
